package com.gzs.space.controller;

import com.gzs.space.entity.User;
import com.gzs.space.response.CommonResponse;
import com.gzs.space.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author GZS
 * @date 2022年04月23日
 */
@RestController
@RequestMapping("/auth")
@CrossOrigin(origins = "*")
public class LoginController {
	@Autowired
	private LoginService loginService;

	/**
	 * 用户注册
	 * @param user
	 * @return
	 */
	@PostMapping("/register")
	public CommonResponse register(@Valid @RequestBody User user){
		return loginService.register(user);
	}

	/**
	 * 用户登录
	 * @param user
	 * @return
	 */
	@PostMapping("/login")
	public CommonResponse login(@RequestBody User user){
		return loginService.login(user);
	}

	@PostMapping("/edit")
	public CommonResponse edit(@RequestBody User user){
		return loginService.edit(user);
	}

	@GetMapping("/allUser")
	public CommonResponse allUser(){
		return loginService.allUser();
	}
}
